import { VisitStatsVO } from "@/api/system/log.api";

/**
 * 计算增长率样式类名
 * @param growthRate 增长率
 */
export const computeGrowthRateClass = (growthRate?: number): string => {
  if (!growthRate) return "text-[--el-color-info]";
  return growthRate > 0
    ? "text-[--el-color-danger]"
    : growthRate < 0
      ? "text-[--el-color-success]"
      : "text-[--el-color-info]";
};

/**
 * 格式化字节单位
 * @param bytes 字节数
 */
export const formatBytes = (bytes: number): string => {
  if (bytes === 0) return "0 B";
  const k = 1024;
  const sizes = ["B", "KB", "MB", "GB", "TB"];
  const i = Math.floor(Math.log(bytes) / Math.log(k));
  return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
};

/**
 * 格式化网络速度
 * @param bytes 字节数/秒
 */
export const formatSpeed = (bytes: number): string => {
  if (bytes < 1024) return `${bytes} B/s`;
  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB/s`;
  return `${(bytes / (1024 * 1024)).toFixed(2)} MB/s`;
};

/**
 * 获取系统资源状态标签类型
 * @param value 使用率(%)
 */
export const getLevelType = (value: number): "success" | "warning" | "danger" => {
  if (value < 30) return "success";
  if (value < 70) return "warning";
  return "danger";
};

/**
 * 获取系统资源状态文本
 * @param value 使用率(%)
 */
export const getLevelText = (value: number): string => {
  if (value < 30) return "正常";
  if (value < 70) return "中等";
  return "紧张";
};

/**
 * 获取进度条状态
 * @param value 使用率(%)
 */
export const getProgressStatus = (value: number): "exception" | undefined => {
  return value >= 70 ? "exception" : undefined;
};

/**
 * 生成问候语
 * @param nickname 用户名
 */
export const generateGreetings = (nickname: string): string => {
  const hours = new Date().getHours();
  if (hours >= 6 && hours < 8) return "晨起披衣出草堂，轩窗已自喜微凉🌅！";
  if (hours >= 8 && hours < 12) return `上午好，${nickname}！`;
  if (hours >= 12 && hours < 18) return `下午好，${nickname}！`;
  if (hours >= 18 && hours < 24) return `晚上好，${nickname}！`;
  return "偷偷向银河要了一把碎星，只等你闭上眼睛撒入你的梦中，晚安🌛！";
};
